package com.company.gas.controller;

import com.company.gas.pojo.IC;
import com.company.gas.service.IICService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/IC")
@Api(tags = "IC营收管理")
public class ICController {

    @Autowired
    private IICService  iICService;

    //显示所有IC卡信息
    @GetMapping("/queryICList")
    @ApiOperation("查询全部IC卡信息")
    public List<IC> queryICList(){
        List<IC> icList = iICService.queryICList();
        return icList;
    }

    //IC卡余额查询
    @GetMapping("/queryICRemain")
    @ApiOperation("查询IC卡余额")
    public IC queryICRemainById(@RequestParam(value = "IC卡号") String icId){
        IC ic = iICService.queryICRemainById(icId);
        System.out.println(ic);
        return ic;
    }

    //IC卡发放管理
    @GetMapping("/newIC")
    @ApiOperation("办理新的IC卡")
    public String newIC(@RequestParam(value = "IC卡号") String icId, @RequestParam(value = "客户ID") String cusId, @RequestParam(value = "IC卡余额") String remainder, @RequestParam(value = "标志位") Integer flag,
                        @RequestParam(value = "创建时间") Date createTime, @RequestParam(value = "创建人") String createBy, @RequestParam(value = "修改时间") Date modifyTime, @RequestParam(value = "修改人") String modifyBy){
        int isNewIC = iICService.newIC(icId,cusId, remainder,flag,createTime,createBy,modifyTime,modifyBy);
        if(isNewIC == 1){
            return "newIC success";
        }else {
            return "newIC fail";
        }
    }

    //修改IC卡信息
    @GetMapping("/updateIC")
    @ApiOperation("修改IC卡信息")
    public String updateIC(@RequestParam(value = "客户ID") String cusId,
                           @RequestParam(value = "IC卡余额") String remainder,
                           @RequestParam(value = "修改时间") Date modifyTime, @RequestParam(value = "修改人") String modifyBy){
        int isUpdateIC = iICService.updateIC(cusId,remainder,modifyTime,modifyBy);
        if(isUpdateIC== 1){
            return "update success";
        }else {
            return "update fail";
        }
    }

    //删除指定IC卡
    @GetMapping("/deleteIC")
    @ApiOperation("删除指定IC卡")
    public String deleteIC(@RequestParam(value = "IC卡号") String icId){
        int isDeleteIC = iICService.deleteIC(icId);
        if(isDeleteIC == 1){
            return "delete success";
        }else {
            return "delete fail";
        }
    }

}
